﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<OptimumInfra.ViewData.ViewDataTemplate>" %>
<%@ Import Namespace="OptimumInfra.Models" %>

<asp:Content ID="Content2" ContentPlaceHolderID="AdminContent" runat="server">
    <h2>Edit Template</h2>
    <% if(TempData["info"] !=null) { %>
    <p style="text-align: center; color: Red;"><%=TempData["info"] %></p>
    <% } %>
        <% using (Html.BeginForm("Edit", "Template", FormMethod.Post, new {enctype = "multipart/form-data", id="templateEdit", name="templateEdit"})) { %>

        <%: Html.ValidationSummary(true, "Account creation was unsuccessful. Please correct the errors and try again.")%>
                <legend>Template Information</legend>
                <br/ />
          <table width="700" style="margin-top: 10px;">

          <tr>
          <td>          
                <div class="editor-label">
                    Template Category
                </div>
            </td> 
            <td>
                <div class="editor-field">

                  <select name="CategoryId" id="CategoryId">
                <option value="">Select Category</option>
                <%
        List<TemplateCategory> option = Model.Categories;
        foreach (TemplateCategory a in option)
        {
            if (Model.CategoryId != a.Id)
            {       
                 %>
                 <option value="<%=a.Id %>"><%= a.Name%></option>               
                 <% 
}
            else
            {
                %>
                 <option value="<%=a.Id %>" selected="true"><%= a.Name%></option>
                <% 
            }
        } 
            
                    %>
                 </select>
                </div>
           </td> 
          </tr>
          <tr>
          <td>          
                <div class="editor-label">
                    <%: Html.LabelFor(template => template.Name)%>
                </div>
            </td> 
            <td>
                <div class="editor-field">
                    <%: Html.TextBoxFor(template => template.Name)%>
                    <%: Html.ValidationMessageFor(template => template.Name)%>
                </div>
           </td> 
          </tr>
           <tr>
               <td>
                <div class="editor-label">
                    <%: Html.LabelFor(m => m.Price)%>
                </div>
                </td> 
                <td>
                <div class="editor-field">
                   <%: Html.TextBoxFor(template => template.Price)%>
                    <%: Html.ValidationMessageFor(template => template.Price)%>
                </div>
                </td> 
            </tr>   
           <tr>
               <td>
                <div class="editor-label">
                    <%: Html.LabelFor(m => m.Manufacturer)%>
                </div>
                </td> 
                <td>
                <div class="editor-field">
                   <%: Html.TextBoxFor(template => template.Manufacturer)%>
                    <%: Html.ValidationMessageFor(template => template.Manufacturer)%>
                </div>
                </td>
  
            </tr>     
          <tr>       
            <td>
                <div class="editor-label">
                    <%: Html.LabelFor(m => m.Description)%>
                </div>
            </td>
            <td>
                <div class="editor-field">
                    <%: Html.TextAreaFor(template => template.Description, 4, 10, new {style = "width: 95%; height:200px;", @class = "textarea" })%>
                    <%: Html.ValidationMessageFor(template => template.Description)%>
                </div>
            </td>
          </tr>
            
            <tr>
               <td>
                <div class="editor-label">
                    <%: Html.LabelFor(m => m.Image)%>
                </div>
                </td> 
                <td>
                <%
               if(Model.Image != "") {
                   
                %>
                
                <img src="/<%=Model.Image %>" width="150" height="100" alt="" title=""/>
                 <%
                 }        
                %>
                <div class="editor-field">
                   <input type="file" id="fileUpload" name="fileUpload"/>
                </div>
                </td>
  
            </tr>    
            <tr>
               <td colspan="2">
                <p>
                    <input type="submit" value="Update" />
                </p>
                </td>
            </tr>         
                
            </table>
    <% } %>
    <script type="text/javascript">
        $(document).ready(function () {

            $("#templateCreate").validate({
                rules: {
                    Name: "required", // simple rule, converted to {required:true} 
                    CategoryId: "required",
                    Price: {
                        required: true,
                        number: true
                    }
                },
                messages: { Name: "* Name is required", CategoryId: "* Please select category", Price: "Must be number" }

            });
        }); 
	  </script>
</asp:Content>
